/**
 * create by young (young2f@outlook.com) on 2020/9/16
 */


'use strict';
import React from 'react';
import {Card, Col, Form, Row, Statistic} from 'antd';

import FormBase from '../../../components/Base/FormBase';
import {connect} from "dva";
import moment from 'moment';
import 'moment/locale/zh-cn';

moment.locale('zh-cn');
const table = 'SalesOrder';
@Form.create()
@connect(({
            user,
            global,
            dynamicLabel,
            material,
            store
          }) => ({...user, ...material, ...dynamicLabel, ...global, ...store}))
export default class ModalStatistics extends FormBase {
  constructor(props) {
    super(props);
    this.state = undefined;
  }

  componentDidMount() {

  }

  getCard(list) {
    return _.map(list, (item) => {
      const {title, value} = item;
      return <Col span={4}>
        <Card
        >
          <Statistic
            title={title}
            value={value}
            precision={3}
            valueStyle={{color: '#35f'}}
          />

        </Card>
      </Col>;
    });
  }

  render() {
    const {values} = this.props;
    const model = this.props[`${table}Model`];

    const list = [];
    _.map(model, (item, key) => {
      const {_type, title} = item;
      if (_type === 'number') {
        let value = 0;
        _.map(values, it => {
          value += parseFloat(it[key]);
        });
        list.push({title, value});
      }
    });
    console.log('list', list);
    return (
      <div>
        <div style={{background: '#ECECEC', padding: '30px'}}>
          <Row gutter={16}>
            {this.getCard(list)}
          </Row>
        </div>
      </div>

    );
  }
}

